package com.coupons.business.partner.dao;

import java.util.List;

import com.coupons.business.common.exception.BaseCouponsAppException;
import com.coupons.business.common.vo.Partner;
import com.coupons.business.common.vo.decorator.PartnerRowMapper;
import com.coupons.business.util.BaseUtilDAO;

public class PartnerDAO extends BaseUtilDAO implements IPartnerDAO {

	public void createPartner(Partner objaPartner)
			throws BaseCouponsAppException 
	{
		int partnerId= getSequenceNextValue(SEQUENCE_NAME);
		Object obj[] = new Object[] { 
				new Integer(partnerId),
				objaPartner.getPartnerName(),
				objaPartner.getDescription(),
				objaPartner.getStatus(),
				objaPartner.getLicenseEndDate(),
				objaPartner.getLastUpdatedUser(),				
				};
		
		int rtnVal = this.saveOrUpdateOrDelete(PARTNER_INSERT_STATEMENT.toString(), obj);
		System.out.println("executed dao");
		if(rtnVal <= 0) {			
			System.out.println("Unable to insert record into Partner table");
			return;
		}

	}
//	"INSERT INTO PARTNER(PARTNER_ID,PARTNER_NAME,DESCRIPTION," +
//	"STATUS,LCSN_END_DT,LAST_UPDT_USER,CRTN_DT,LAST_UPDT_DT) VALUES(?,?,?,?,?,?,SYSDATE,SYSDATE)";
	
	
	public void updatePartner(Partner objaPartner)
			throws BaseCouponsAppException {
		

	}

	public Partner getPartner(int partnerId) throws BaseCouponsAppException {
		try {
			Object objParams[] = new Object[]{new Integer(partnerId)};
			List<Object> list = this.findRecords(GET_PARTNER_STATEMENT, objParams,new PartnerRowMapper());
			
			if (null!=list && list.size()>0){
				
					return (Partner)list.get(0);
			}
			else
				return null;
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		System.out.println("ok");
		return null;
	}

	public List<Partner> getAllPartners() throws BaseCouponsAppException {
		try {
			List list = this.findRecords(GET_ALL_PARTNERS_STATEMENT, new PartnerRowMapper());
			return list;
		} catch (BaseCouponsAppException e) {			
			e.printStackTrace();
			throw e;
		}		
	}
}
